/* 
 * File:   Editor.cpp
 * Author: agu
 * 
 * Created on 4 de junio de 2014, 18:18
 */
#include <iostream>
#include "Editor.h"
#include "NuevaCampania.h"

Editor::Editor(Glib::RefPtr<Gtk::Application> aplicacion){
    this->app = aplicacion;
    //Load the GtkBuilder file and instantiate its widgets:
    this->builder = Gtk::Builder::create();
    try {
        this->builder->add_from_file("editor.glade");
    } catch (const Glib::FileError& ex) {
        std::cout << "FileError: " << ex.what() << std::endl;

    } catch (const Glib::MarkupError& ex) {
        std::cout << "MarkupError: " << ex.what() << std::endl;

    } catch (const Gtk::BuilderError& ex) {
        std::cout << "BuilderError: " << ex.what() << std::endl;

    }
    this->loadWidgets();
    this->connectWidgets();
}

void Editor::loadWidgets() {
    this->builder->get_widget("window", this->window);
    this->builder->get_widget("button_new", this->button_new);
    this->builder->get_widget("button_del", this->button_del);
    this->builder->get_widget("button_quit", this->button_quit);

}

void Editor::connectWidgets() {
    this->window->signal_hide().connect(sigc::mem_fun(this, &Editor::close));
    this->button_quit->signal_clicked().connect(sigc::mem_fun(this, &Editor::close));
    this->button_new->signal_clicked().connect(sigc::mem_fun(this, &Editor::newCampain));
    this->button_del->signal_clicked().connect(sigc::mem_fun(this, &Editor::deleteCampain));
}

Editor::~Editor() {
    delete window;
}

void Editor::close() {
    this->window->close();
}

void Editor::newCampain() {
    newCamp.run();
}


void Editor::deleteCampain() {
    std::cout << "Eliminar campaña" << std::endl;
}

void Editor::run() {
    app->run(*this->window);
}